package com.buss.util.map;

import com.buss.util.Constant;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 * @author YI
 *
 */
//@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class Result {
	public Map<String, Object> success(){
		Map<String, Object> success=new HashMap<String,Object>();
		success.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_SUCCSS_CODE);
		return success;
	}
	//请求超时
	public Map<String, Object> fail(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.SIGN_TIME_OUT_MSG);
		return fail;
	}
	//签名验证未通过
	public Map<String, Object> signFail(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.SIGN_VALIDATE_ERROR_MSG);
		return fail;
	}
	//计算签名失败
	public Map<String, Object> signError(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.CREATE_SIGN_ERROR_MSG);
		return fail;
	}
	//自定义错误提示
	public Map<String, Object> addErrorMsg(String msg){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, msg);
		return fail;
	}
	//自定义错误提示
	public Map<String, Object> addErrorMsg00000(String msg){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_SUCCSS_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, msg);
		return fail;
	}

	//token错误
	public Map<String, Object> tokenError(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.TOKEN_NOT_FIND_ERROR_MSG);
		return fail;
	}


	//登陆错误
	public Map<String, Object> loginError(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
//		fail.put(Constant.COMMON_RETURN_NODE_MSG, encode(Constant.PARAM_NOT_FIND_ERROR_MSG));
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.LOGIN_ERROR_MSG);
		return fail;
	}

	//验证码不正确
	public Map<String, String> captchaError(){
		Map<String, String> fail=new HashMap<String, String>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
//		fail.put(Constant.COMMON_RETURN_NODE_MSG, encode(Constant.CAPTCHA_ERROR_MSG));
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.CAPTCHA_ERROR_MSG);
		return fail;
	}

	//参数为空
	public Map<String, Object> inputParamIsNullError(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.PARAM_NOT_FIND_ERROR_MSG);
		return fail;
	}
	//参数为空
	public Map<String, Object> inputJsonIsNullError(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.JSON_NOT_FIND_ERROR_MSG);
		return fail;
	}

	//请求API接口错误,原因是返回的消息为null
	public Map<String, Object> apiFail(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.API_FAIL_MSG);
		return fail;
	}

	//请求API接口错误,原因是返回的消息不能转为JSON
	public Map<String, Object> apiFailNoJson(){
		Map<String, Object> fail=new HashMap<String,Object>();
		fail.put(Constant.COMMON_RETURN_NODE_CODE, Constant.COMMON_RETURN_FAIL_CODE);
		fail.put(Constant.COMMON_RETURN_NODE_MSG, Constant.API_FAIL_NOJSON_MSG);
		return fail;
	}


	//对要传递的中文进行编码
	public static String encode(String s){
		try {
			s = URLEncoder.encode(s, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return s;
	}
	

}
